<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Class acount extends CI_Controller
 * @author
 * 用户
 */
class Acount extends CRUD_Controller
{

	function __construct()
	{
		parent::__construct();
        

		$this->rules = array(
			"rule" => array(
				array(
					"field" => "timeline",
					"label" => lang('time'),
					"rules" => "trim"
				)
			)
		);

	}
    protected function _index_where(){
        $arr =array('phone_valid'=>1);
        return $arr;
    }
    protected function _edit_data(){
        $form=$this->input->post();
        if (isset($form['is_pwd'])) {
            if (!empty($form['is_pwd'])&&$form['is_pwd']!='') {
                $form['password'] = passwd(000000);
                unset($form['is_pwd']);
            }
        }
        return $form;
    }
	 // 搜索
    public function search($page=1){
        $title = "会员中心";
        $vdata['title'] = $title;
        
        $limit = $this->page_limit;
        $this->input->get('limit',TRUE) and is_numeric($this->input->get('limit')) AND $limit = $this->input->get('limit');
        $order = $this->input->get('order',TRUE) ? $this->input->get('order',TRUE):FALSE;
        $where = array('phone_valid'=>1);
        if ($ctype = $this->input->get('ctype',TRUE) AND is_numeric($ctype)) {
            $where['ctype'] = $ctype;
        }
     

        if($this->input->get('uname',TRUE)){
            $where_q = array(
           'like phone'=> array('phone',$this->input->get('uname',TRUE)),
            'or_like uname'=> array('uname',$this->input->get('uname',TRUE))
          );
            $where = array_merge($where,$where_q);
        }
        if($this->input->get('starttime',TRUE)){
            $starttime=strtotime($this->input->get('starttime',TRUE));
            $where_s=array('timeline >'=>$starttime);
            $where = array_merge($where,$where_s);
        }
        if($this->input->get('endtime',TRUE)){
            $endtime=strtotime($this->input->get('endtime',TRUE));
            $where_e=array('timeline <'=>$endtime);
            $where = array_merge($where,$where_e);
        }
        $vdata['pages'] = $this->_pages(site_url($this->class.'/search/'),$limit,$where,4);
        $vdata['list'] = $this->model->get_list($limit,$limit*($page-1),$order,$where);
        //print_r($this->db->last_query());
        $vdata['count'] = $this->model->get_count_all($where);
        $this->_display($vdata,$this->class.'_index.php');
    }
    public function audit($key = FALSE){
        $this->load->model('acount_model','acount','default');
        if (!$key AND $this->input->post('ids') ) {
            $key = explode(',',$this->input->post('ids'));
        }else{
            $vdata = array('status'=>0,'msg'=>lang('modules_no_id'));
        }
        $where = FALSE;
        $audit = $this->input->post('audit');
        if ($audit) {
            $audit=1;
        }else{
            $audit=0;
        }
        $msg = array(lang('modules_audit_false'),lang('modules_audit_true'));
        if (!isset($vdata['status'])) {

            $res=$this->acount->updateInfo(array('audit'=>$audit),array('id'=>$key[0]));
            if ($res) {
                $vdata = array('status'=>1,'msg'=>$msg[$audit]);
//                if (is_array($key)) {
//                    $this->mlogs->add('audit',lang('modules_audit_id').$this->input->post('ids').lang('modules_audit_for').$audit);
//                }else{
//                    $this->mlogs->add('audit',lang('modules_audit_id').$key.lang('modules_audit_for').$audit);
//                }
            }else{
                $vdata = array('status'=>0,'msg'=>lang('modules_audit_err_select'));
            }
        }

        if($this->input->is_ajax_request()){
            $this->output->set_content_type('application/json')->set_output(json_encode($vdata));
        }else{
            $this->load->view('msg',$vdata);
        }
    }
}
